//
//  XMEditUserViewController.m
//  XunMi
//
//  Created by MacBook on 2024/2/28.
//  Copyright © 2024 TieZhu. All rights reserved.
//

#import "XMEditUserViewController.h"
#import "XMEditUserLineView.h"
#import "XMEditUserHeadView.h"
#import <BRPickerView/BRPickerView.h>
#import <TZImagePickerController/TZImagePickerController.h>
#import "XMHeightChooseView.h"
#import "XMUserDetailRemarkView.h"
#import "XMLoginPrivacyTipView.h"
#import "XMLoginRecordView.h"
#import "XMAudioPlayer.h"
#import "XMIntroduceViewController.h"
#import "XMRecentPhotosListViewController.h"
#import "XMChooseHeadTipView.h"

static CGFloat const kLineHeight = 48.0;

@interface XMEditUserViewController () <UIScrollViewDelegate, TZImagePickerControllerDelegate, UIImagePickerControllerDelegate, UINavigationControllerDelegate>
@property (nonatomic, strong) UIScrollView *scrollerView;
@property (nonatomic, strong) XMEditUserHeadView *headerView;
@property (nonatomic, strong) XMEditUserLineView *voiceView;
@property (nonatomic, strong) XMEditUserLineView *videoView;
@property (nonatomic, strong) XMEditUserLineView *nameView;
@property (nonatomic, strong) XMEditUserLineView *sexView;
@property (nonatomic, strong) XMEditUserLineView *ageView;
@property (nonatomic, strong) XMEditUserLineView *birView;
@property (nonatomic, strong) XMEditUserLineView *cityView;
@property (nonatomic, strong) XMEditUserLineView *heightView;
@property (nonatomic, strong) XMEditUserLineView *xueliView;
@property (nonatomic, strong) XMEditUserLineView *zhiyeView;
@property (nonatomic, strong) XMEditUserLineView *signView;
@property (nonatomic, strong) XMEditUserLineView *jieshaoView;
@property (nonatomic, strong) XMEditUserLineView *photoView;
@property (nonatomic, strong) XMEditUserLineView *qingganView;
@property (nonatomic, strong) XMEditUserLineView *techangView;
@property (nonatomic, strong) XMEditUserLineView *shouruView;
@property (nonatomic, strong) XMEditUserLineView *fangView;
@property (nonatomic, strong) XMEditUserLineView *cheView;
@property (nonatomic, strong) XMHeightChooseView *heightChooseV;
@property (nonatomic, strong) XMUserModel *userModel;
@property (nonatomic, strong) XMUserDetailRemarkView *editNameView;
@property (nonatomic, strong) XMUserDetailRemarkView *editSignView;
@property (nonatomic, strong) XMLoginPrivacyTipView *voiceTipView;
@property (nonatomic, copy) NSString *filePath;
@property (nonatomic, strong) XMChooseHeadTipView *tipView;
@end

@implementation XMEditUserViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    [self setupSubviews];
    [self viewBlock];
    [self userInfo];
}
- (void)viewWillDisappear:(BOOL)animated {
    [super viewWillDisappear:animated];
    [self stopPlay];
}

- (void)userInfo {
    NSMutableDictionary *dic = @{
        @"module": @"1"
    }.mutableCopy;
    [YHNetworkManager.sharedInstance postWithUrl:@"api/user/obtain" parameters:dic completeBlock:^(XMResponseTip * _Nonnull tip, id  _Nullable result) {
        if (tip.success) {
            XMUserModel *userModel = [XMUserModel mj_objectWithKeyValues:result];
            self.userModel = userModel;
            [self.headerView.stateBtn setTitle:userModel.avatar_verify == 0 ? @"头像审核中" : @"更换头像" forState:UIControlStateNormal];
            [self.headerView.imgV sd_setImageWithURL:kStringToUrl(userModel.avatar.file_url) placeholderImage:userModel.isMan ? kManHeadImg : kWomanHeadImg];
            //
            self.nameView.contentStr = userModel.nickname;
            self.nameView.stateBtn.hidden = userModel.name_verify == 0 ? NO : YES;
            
            self.sexView.contentStr = userModel.isMan ? @"男" : @"女";
            self.birView.contentStr = [XMUtil isBlankString:userModel.birthday] ? @"请选择" :  userModel.birthday;
            
            self.ageView.contentStr = [XMUtil isBlankString:userModel.age] ? @"请选择" :  kStringFormat(@"%@岁",userModel.age);
            
            if (![XMUtil isBlankString:userModel.province]) {
                self.cityView.contentStr = kStringFormat(@"%@ %@",userModel.province, userModel.city);
            } else {
                self.cityView.contentStr = @"请选择";
            }
            
            if (![XMUtil isBlankString:userModel.height] &&
                ![XMUtil isBlankString:userModel.weight]) {
                self.heightView.contentStr = kStringFormat(@"%@cm-%@kg",userModel.height, userModel.weight);
            } else {
                self.heightView.contentStr = @"请选择";
            }
            
            self.xueliView.contentStr = [XMUtil isBlankString:userModel.education] ? @"请选择" : userModel.education;
            
            self.zhiyeView.contentStr = [XMUtil isBlankString:userModel.occupation] ? @"请选择" : userModel.occupation;
            
            self.signView.contentStr = userModel.text_intro;
            
//            self.jieshaoView.contentStr = userModel.introduce;
            
            self.qingganView.contentStr = [XMUtil isBlankString:userModel.emotion] ? @"请选择" : userModel.emotion;
            self.techangView.contentStr = [XMUtil isBlankString:userModel.hobby] ? @"请选择" : userModel.hobby;
            self.shouruView.contentStr = [XMUtil isBlankString:userModel.income] ? @"请选择" : userModel.income;
            self.fangView.contentStr = [XMUtil isBlankString:userModel.purchase_house] ? @"请选择" : userModel.purchase_house;
            self.cheView.contentStr = [XMUtil isBlankString:userModel.buying_car] ? @"请选择" : userModel.buying_car;
            
            
            if ([XMUtil isBlankString:userModel.voice_intro.file_url]) {
                self.voiceView.goLa.text = @"去录制";
                self.voiceView.icon.image = kGetImage(@"edit_voice");
                self.voiceView.titleLa.textColor = kHEX(@"9A9A9A");
                self.voiceView.titleLa.text = @"去录制语音介绍吧~";
            } else {
                self.voiceView.goLa.text = @"去更换";
                self.voiceView.icon.image = kGetImage(@"edit_voice1");
                self.voiceView.titleLa.textColor = kHEX(@"1F1F1F");
                self.voiceView.titleLa.text = @"播放已录的语音";
            }
            
            if ([XMUtil isBlankString:userModel.video_cover.file_url]) {
                self.videoView.goLa.text = @"去录制";
                self.videoView.titleLa.textColor = kHEX(@"9A9A9A");
                self.videoView.titleLa.text = @"去录个视频封面吧~";
            } else {
                self.videoView.goLa.text = @"去更换";
                self.videoView.titleLa.textColor = kHEX(@"1F1F1F");
                self.videoView.titleLa.text = @"已录制视频封面";
            }
        }
    }];
}

#pragma mark - setupSubviews
- (void)setupSubviews {
    self.navView.backgroundColor = kHEXA(@"FFFFFF", 0);
    [self.navLeft2Btn setTitle:@"编辑资料" forState:UIControlStateNormal];
    self.view.backgroundColor = kHEX(@"F2F2F2");
    self.scrollerView = [[UIScrollView alloc] init];
    self.scrollerView.backgroundColor = kHEX(@"F2F2F2");
    self.scrollerView.delegate = self;
    [self.view addSubview:self.scrollerView];
    [self.scrollerView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.edges.equalTo(self.view).insets(UIEdgeInsetsMake(kNavBarAndStatusBarHeight, 0, 0, 0));
    }];
    
    UILabel *la = [[UILabel alloc] init];
    la.text = @"填写真实资料，匹配度会更高哦～";
    la.textColor = kHEX(@"9A9A9A");
    la.font = kUIFont(12);
    [_scrollerView addSubview:la];
    
    [la mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(_scrollerView).offset(7);
        make.left.equalTo(_scrollerView).offset(30);
        make.height.mas_equalTo(18);
        make.right.equalTo(_scrollerView).offset(-30);
        make.width.mas_equalTo(kScreenWidth - 60);
    }];
    
    self.headerView = [XMEditUserHeadView viewFromXib];
    
    [_scrollerView addSubview:_headerView];
    [_headerView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.size.mas_equalTo(CGSizeMake(96, 96));
        make.centerX.equalTo(la);
        make.top.equalTo(la.mas_bottom).offset(30);
    }];
    
    UIView *view1 = [[UIView alloc] initWithFrame:CGRectZero];
    kCornerRadius(view1, 10, 0, UIColor.clearColor);
    [_scrollerView addSubview:view1];
    view1.backgroundColor = UIColor.whiteColor;
    
    [view1 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(_scrollerView).offset(20);
        make.right.equalTo(_scrollerView).offset(-20);
        make.height.mas_equalTo(kLineHeight * 2);
        make.top.equalTo(_headerView.mas_bottom).offset(45);
    }];
    
    _voiceView = [XMEditUserLineView viewFromXib];
    _voiceView.showIcon = YES;
    _voiceView.showGoLa = YES;
    _voiceView.showContentLa = YES;
    _voiceView.titleLa.textColor = k1F1F1F;
    _voiceView.titleLa.text = @"播放已录的语音";
    _voiceView.icon.image = kGetImage(@"edit_voice");
    
    [view1 addSubview:_voiceView];
    [_voiceView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.equalTo(view1);
        make.top.equalTo(view1).offset(0);
        make.height.mas_equalTo(kLineHeight);
    }];
    
    _videoView = [XMEditUserLineView viewFromXib];
    _videoView.showIcon = YES;
    _videoView.showGoLa = YES;
    _videoView.showContentLa = YES;
    _videoView.titleLa.text = @"去录个视频封面吧～";
    _videoView.icon.image = kGetImage(@"edit_video");
    _videoView.line.hidden = YES;
    
    [view1 addSubview:_videoView];
    [_videoView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.equalTo(view1);
        make.top.equalTo(_voiceView.mas_bottom).offset(0);
        make.height.mas_equalTo(kLineHeight);
    }];
    
    UILabel *la1 = [[UILabel alloc] init];
    NSString *str1 = @"基本资料";
    NSMutableAttributedString *att1 = [[NSMutableAttributedString alloc] initWithString:str1];
    
    [att1 addAttributes:@{NSForegroundColorAttributeName:kHEX(@"1F1F1F"),NSFontAttributeName:kUIFontBold(16)} range:[str1 rangeOfString:@"基本资料"]];
    
//    [att1 addAttributes:@{NSForegroundColorAttributeName:kAppMainColor, NSFontAttributeName:kUIFont(12)} range:[str1 rangeOfString:@"（必填）"]];
    
    la1.attributedText = att1;
    [_scrollerView addSubview:la1];
    [la1 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(_scrollerView).offset(30);
        make.top.equalTo(view1.mas_bottom).offset(30);
        make.height.mas_equalTo(20);
    }];
    
    //
    UIView *view2 = [[UIView alloc] initWithFrame:CGRectZero];
    kCornerRadius(view2, 10, 0, UIColor.clearColor);
    [_scrollerView addSubview:view2];
    view2.backgroundColor = UIColor.whiteColor;
    
    [view2 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(_scrollerView).offset(20);
        make.right.equalTo(_scrollerView).offset(-20);
        make.height.mas_equalTo(kLineHeight * 9);
        make.top.equalTo(la1.mas_bottom).offset(15);
    }];
    
    _nameView = [XMEditUserLineView viewFromXib];
    _nameView.showIcon = NO;
    _nameView.showGoLa = NO;
    _nameView.showContentLa = YES;
    _nameView.titleLa.text = @"昵称";
    
    [view2 addSubview:_nameView];
    [_nameView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.equalTo(view2);
        make.top.equalTo(view2).offset(0);
        make.height.mas_equalTo(kLineHeight);
    }];
    
    _sexView = [XMEditUserLineView viewFromXib];
    _sexView.showIcon = NO;
    _sexView.showGoLa = NO;
    _sexView.showContentLa = YES;
    _sexView.titleLa.text = @"性别";
    
    [view2 addSubview:_sexView];
    [_sexView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.equalTo(view2);
        make.top.equalTo(_nameView.mas_bottom).offset(0);
        make.height.mas_equalTo(kLineHeight);
    }];
    
    _ageView = [XMEditUserLineView viewFromXib];
    _ageView.showIcon = NO;
    _ageView.showGoLa = NO;
    _ageView.showContentLa = YES;
    _ageView.titleLa.text = @"年龄";
    [view2 addSubview:_ageView];
    [_ageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.equalTo(view2);
        make.top.equalTo(_sexView.mas_bottom).offset(0);
        make.height.mas_equalTo(kLineHeight);
    }];
    
    _birView = [XMEditUserLineView viewFromXib];
    _birView.showIcon = NO;
    _birView.showGoLa = NO;
    _birView.showContentLa = YES;
    _birView.titleLa.text = @"生日";
    [view2 addSubview:_birView];
    [_birView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.equalTo(view2);
        make.top.equalTo(_ageView.mas_bottom).offset(0);
        make.height.mas_equalTo(kLineHeight);
    }];
    
    _cityView = [XMEditUserLineView viewFromXib];
    _cityView.showIcon = NO;
    _cityView.showGoLa = NO;
    _cityView.showContentLa = YES;
    _cityView.titleLa.text = @"城市";
    
    [view2 addSubview:_cityView];
    [_cityView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.equalTo(view2);
        make.top.equalTo(_birView.mas_bottom).offset(0);
        make.height.mas_equalTo(kLineHeight);
    }];
    
    _heightView = [XMEditUserLineView viewFromXib];
    _heightView.showIcon = NO;
    _heightView.showGoLa = NO;
    _heightView.showContentLa = YES;
    _heightView.titleLa.text = @"身高/体重";
    
    [view2 addSubview:_heightView];
    [_heightView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.equalTo(view2);
        make.top.equalTo(_cityView.mas_bottom).offset(0);
        make.height.mas_equalTo(kLineHeight);
    }];
    
    _xueliView = [XMEditUserLineView viewFromXib];
    _xueliView.showIcon = NO;
    _xueliView.showGoLa = NO;
    _xueliView.showContentLa = YES;
    _xueliView.titleLa.text = @"学历";
    
    [view2 addSubview:_xueliView];
    [_xueliView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.equalTo(view2);
        make.top.equalTo(_heightView.mas_bottom).offset(0);
        make.height.mas_equalTo(kLineHeight);
    }];
    
    _zhiyeView = [XMEditUserLineView viewFromXib];
    _zhiyeView.showIcon = NO;
    _zhiyeView.showGoLa = NO;
    _zhiyeView.showContentLa = YES;
    _zhiyeView.titleLa.text = @"职业";
    
    [view2 addSubview:_zhiyeView];
    [_zhiyeView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.equalTo(view2);
        make.top.equalTo(_xueliView.mas_bottom).offset(0);
        make.height.mas_equalTo(kLineHeight);
    }];
    
    _signView = [XMEditUserLineView viewFromXib];
    _signView.showIcon = NO;
    _signView.showGoLa = NO;
    _signView.showContentLa = YES;
    _signView.titleLa.text = @"个性签名";
    _signView.line.hidden = YES;
    
    [view2 addSubview:_signView];
    [_signView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.equalTo(view2);
        make.top.equalTo(_zhiyeView.mas_bottom).offset(0);
        make.height.mas_equalTo(kLineHeight);
    }];
    
    //
    UILabel *la2 = [[UILabel alloc] init];
    NSString *str2 = @"自我介绍（建议填）";
    NSMutableAttributedString *att2 = [[NSMutableAttributedString alloc] initWithString:str2];
    
    [att2 addAttributes:@{NSForegroundColorAttributeName:kHEX(@"1F1F1F"),NSFontAttributeName:kUIFontBold(16)} range:[str2 rangeOfString:@"自我介绍"]];
    
    [att2 addAttributes:@{NSForegroundColorAttributeName:kAppMainColor, NSFontAttributeName:kUIFont(12)} range:[str2 rangeOfString:@"（建议填）"]];
    
    la2.attributedText = att2;
    
    [_scrollerView addSubview:la2];
    
    [la2 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(_scrollerView).offset(30);
        make.top.equalTo(view2.mas_bottom).offset(30);
        make.height.mas_equalTo(20);
    }];
    
    //
    UIView *view3 = [[UIView alloc] initWithFrame:CGRectZero];
    kCornerRadius(view3, 10, 0, UIColor.clearColor);
    [_scrollerView addSubview:view3];
    view3.backgroundColor = UIColor.whiteColor;
    
    [view3 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(_scrollerView).offset(20);
        make.right.equalTo(_scrollerView).offset(-20);
        make.height.mas_equalTo(kLineHeight * 2);
        make.top.equalTo(la2.mas_bottom).offset(15);
    }];
    
    _jieshaoView = [XMEditUserLineView viewFromXib];
    _jieshaoView.showIcon = NO;
    _jieshaoView.showGoLa = YES;
    _jieshaoView.goLa.text = @"去完善";
    _jieshaoView.showContentLa = YES;
    _jieshaoView.titleLa.text = @"自我介绍";
    
    [view3 addSubview:_jieshaoView];
    [_jieshaoView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.equalTo(view3);
        make.top.equalTo(view3).offset(0);
        make.height.mas_equalTo(kLineHeight);
    }];
    
    _photoView = [XMEditUserLineView viewFromXib];
    _photoView.showIcon = NO;
    _photoView.showGoLa = YES;
    _photoView.goLa.text = @"去上传";
    _photoView.showContentLa = YES;
    _photoView.contentStr = @"（最多9张）";
    _photoView.titleLa.text = @"近期照片";
    _photoView.line.hidden = YES;
    
    [view3 addSubview:_photoView];
    [_photoView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.equalTo(view3);
        make.top.equalTo(_jieshaoView.mas_bottom).offset(0);
        make.height.mas_equalTo(kLineHeight);
    }];
    
    //
    UILabel *la3 = [[UILabel alloc] init];
    NSString *str3 = @"更多资料（建议填）";
    NSMutableAttributedString *att3 = [[NSMutableAttributedString alloc] initWithString:str3];
    
    [att3 addAttributes:@{NSForegroundColorAttributeName:kHEX(@"1F1F1F"),NSFontAttributeName:kUIFontBold(16)} range:[str3 rangeOfString:@"更多资料"]];
    
    [att3 addAttributes:@{NSForegroundColorAttributeName:kAppMainColor, NSFontAttributeName:kUIFont(12)} range:[str3 rangeOfString:@"（建议填）"]];
    
    la3.attributedText = att3;
    
    [_scrollerView addSubview:la3];
    
    [la3 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(_scrollerView).offset(30);
        make.top.equalTo(view3.mas_bottom).offset(30);
        make.height.mas_equalTo(20);
    }];
    
    //
    UIView *view4 = [[UIView alloc] initWithFrame:CGRectZero];
    kCornerRadius(view4, 10, 0, UIColor.clearColor);
    [_scrollerView addSubview:view4];
    view4.backgroundColor = UIColor.whiteColor;
    
    [view4 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(_scrollerView).offset(20);
        make.right.equalTo(_scrollerView).offset(-20);
        make.height.mas_equalTo(kLineHeight * 5);
        make.top.equalTo(la3.mas_bottom).offset(15);
        make.bottom.equalTo(_scrollerView).offset(-kBottomSafeHeight - 10);
    }];
    
    _qingganView = [XMEditUserLineView viewFromXib];
    _qingganView.showIcon = NO;
    _qingganView.showGoLa = NO;
    _qingganView.showContentLa = YES;
    _qingganView.titleLa.text = @"情感状态";
    
    [view4 addSubview:_qingganView];
    [_qingganView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.equalTo(view4);
        make.top.equalTo(view4).offset(0);
        make.height.mas_equalTo(kLineHeight);
    }];
    
    _techangView = [XMEditUserLineView viewFromXib];
    _techangView.showIcon = NO;
    _techangView.showGoLa = NO;
    _techangView.showContentLa = YES;
    _techangView.titleLa.text = @"特长爱好";
    
    [view4 addSubview:_techangView];
    [_techangView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.equalTo(view4);
        make.top.equalTo(_qingganView.mas_bottom).offset(0);
        make.height.mas_equalTo(kLineHeight);
    }];
    
    _shouruView = [XMEditUserLineView viewFromXib];
    _shouruView.showIcon = NO;
    _shouruView.showGoLa = NO;
    _shouruView.showContentLa = YES;
    _shouruView.titleLa.text = @"月收入";
    
    [view4 addSubview:_shouruView];
    [_shouruView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.equalTo(view4);
        make.top.equalTo(_techangView.mas_bottom).offset(0);
        make.height.mas_equalTo(kLineHeight);
    }];
    
    _fangView = [XMEditUserLineView viewFromXib];
    _fangView.showIcon = NO;
    _fangView.showGoLa = NO;
    _fangView.showContentLa = YES;
    _fangView.titleLa.text = @"有无房产";
    
    [view4 addSubview:_fangView];
    [_fangView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.equalTo(view4);
        make.top.equalTo(_shouruView.mas_bottom).offset(0);
        make.height.mas_equalTo(kLineHeight);
        
    }];
    
    _cheView = [XMEditUserLineView viewFromXib];
    _cheView.showIcon = NO;
    _cheView.showGoLa = NO;
    _cheView.showContentLa = YES;
    _cheView.titleLa.text = @"是否购车";
    
    [view4 addSubview:_cheView];
    [_cheView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.equalTo(view4);
        make.top.equalTo(_fangView.mas_bottom).offset(0);
        make.height.mas_equalTo(kLineHeight);
    }];
    
    [self.view bringSubviewToFront:self.navView];
    
}

// 1 图片 2视频
- (void)showImagePickerType:(NSInteger)type {
    //    if (kUserModel.avatar_status == 1) {
    //        [MBProgressHUD showHUDMsg:@"头像审核中.." toView:nil];
    //        return;
    //    }
    TZImagePickerController *imagePicker = [[TZImagePickerController alloc] initWithMaxImagesCount:1 columnNumber:4 delegate:self pushPhotoPickerVc:YES];
    imagePicker.isSelectOriginalPhoto = type == 1 ? YES : NO;
    
    imagePicker.allowTakeVideo = type == 1 ? NO : YES;
    imagePicker.allowPickingVideo = type == 1 ? NO : YES;
    
    imagePicker.allowTakePicture = type == 1 ? YES : NO;
    imagePicker.allowPickingImage = type == 1 ? YES : NO;
    
    imagePicker.allowPickingGif = NO;
    [imagePicker setUiImagePickerControllerSettingBlock:^(UIImagePickerController *imagePickerController) {
        imagePickerController.videoQuality = UIImagePickerControllerQualityTypeHigh;
    }];
    imagePicker.navigationBar.barTintColor = UIColor.whiteColor;
    imagePicker.oKButtonTitleColorNormal = kAppMainColor;
    imagePicker.oKButtonTitleColorDisabled = kAppMainColor;
    imagePicker.barItemTextColor = UIColor.blackColor;
    imagePicker.navigationBar.translucent = NO;
    [imagePicker.navigationBar setTitleTextAttributes:@{NSForegroundColorAttributeName: [UIColor blackColor]}];
    imagePicker.navigationBar.tintColor = UIColor.blackColor;
    if (@available(iOS 13.0, *)) {
        UINavigationBarAppearance *barAppearance = [[UINavigationBarAppearance alloc] init];
        barAppearance.backgroundColor = imagePicker.navigationBar.barTintColor;
        barAppearance.titleTextAttributes = imagePicker.navigationBar.titleTextAttributes;
        imagePicker.navigationBar.standardAppearance = barAppearance;
        imagePicker.navigationBar.scrollEdgeAppearance = barAppearance;
    }
    imagePicker.iconThemeColor = kAppMainColor;
    imagePicker.showPhotoCannotSelectLayer = YES;
    imagePicker.cannotSelectLayerColor = [[UIColor whiteColor] colorWithAlphaComponent:0.8];
    [imagePicker setPhotoPickerPageUIConfigBlock:^(UICollectionView *collectionView, UIView *bottomToolBar, UIButton *previewButton, UIButton *originalPhotoButton, UILabel *originalPhotoLabel, UIButton *doneButton, UIImageView *numberImageView, UILabel *numberLabel, UIView *divideLine) {
        [previewButton setTitleColor:kAppMainColor forState:UIControlStateNormal];
        [originalPhotoButton setImage:kGetImage(@"ic_dyn_origin_s") forState:UIControlStateSelected];
    }];
    [imagePicker setNavLeftBarButtonSettingBlock:^(UIButton *leftButton) {
        [leftButton setImage:[UIImage imageNamed:@"xm_arrow_back"] forState:UIControlStateNormal];
        [leftButton setImageEdgeInsets:UIEdgeInsetsMake(0, -10, 0, 20)];
    }];
    imagePicker.statusBarStyle = UIStatusBarStyleDefault;
    imagePicker.showSelectedIndex = YES;
    imagePicker.sortAscendingByModificationDate = NO;
    imagePicker.showSelectBtn = NO;
    imagePicker.allowCrop = YES;
    imagePicker.needCircleCrop = NO;
    NSInteger left = 10;
    NSInteger widthHeight = self.view.width - 2 * left;
    NSInteger top = (self.view.height - widthHeight) / 2;
    if ([TZCommonTools tz_isLandscape]) {
        top = 10;
        widthHeight = self.view.height - 2 * left;
        left = (self.view.width - widthHeight) / 2;
    }
    imagePicker.cropRect = CGRectMake(left, top, widthHeight, widthHeight);
    imagePicker.scaleAspectFillCrop = YES;
    imagePicker.modalPresentationStyle = UIModalPresentationFullScreen;
    [self presentViewController:imagePicker animated:YES completion:nil];
}

- (void)takePhoto {
    if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera]) {
        UIImagePickerController *imagePicker = [[UIImagePickerController alloc] init];
        imagePicker.delegate = self;
        imagePicker.sourceType = UIImagePickerControllerSourceTypeCamera;
        [self presentViewController:imagePicker animated:YES completion:nil];
    } else {
        NSLog(@"Camera is not available.");
    }
}
#pragma mark - UIImagePickerControllerDelegate
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary<UIImagePickerControllerInfoKey, id> *)info {
    UIImage *image = info[UIImagePickerControllerOriginalImage];
    [self.headerView.imgV setImage:image];
    [picker dismissViewControllerAnimated:YES completion:nil];
    [GKCover hideCover];
    [self uploadHeadImg:image];
}

- (void)imagePickerControllerDidCancel:(UIImagePickerController *)picker {
    [picker dismissViewControllerAnimated:YES completion:nil];
}

- (void)uploadHeadImg:(UIImage *)image {
    [MBProgressHUD showHUDActivityMsg:nil toView:kWindow];
    [XMUploadManager.sharedInstance uploadImage:image compress:YES person_id:self.userModel.person_id complete:^(XMUploadResultModel * _Nonnull result) {
        if (result.success) {
            NSString *imgJson = [[XMUploadResultModel paramDic:result fileType:@"1"] jsonStringEncoded];
            XMWeakSelf(self);
            [self updateUserInfoWithType:XMEditUserTypeHeader content:imgJson complete:^(XMResponseTip *tip, id  _Nullable result1) {
                XMStrongSelf(self);
                if (tip.success) {
                    [self.headerView.imgV setImage:image];
                    kUserModel.avatar_verify = 0;
                    kUserModel.avatar.file_url = result.url;
                    [self.headerView.stateBtn setTitle:@"头像审核中" forState:UIControlStateNormal];
                }
            }];
        } else {
            [MBProgressHUD hideHUD];
            [MBProgressHUD showHUDMsg:@"图片上传失败!" toView:nil];
        }
    }];
}

#pragma mark - TZImagePickerControllerDelegate
- (void)tz_imagePickerControllerDidCancel:(TZImagePickerController *)picker {
}
- (void)imagePickerController:(TZImagePickerController *)picker didFinishPickingPhotos:(NSArray<UIImage *> *)photos sourceAssets:(NSArray *)assets isSelectOriginalPhoto:(BOOL)isSelectOriginalPhoto infos:(NSArray<NSDictionary *> *)infos {
    if (photos.count > 0) {
        [GKCover hideCover];
        [self uploadHeadImg:photos.firstObject];
    }
}

- (void)imagePickerController:(TZImagePickerController *)picker didFinishPickingVideo:(UIImage *)coverImage sourceAssets:(PHAsset *)asset {
    [MBProgressHUD showHUDActivityMsg:nil toView:kWindow];
    [[TZImageManager manager] getVideoOutputPathWithAsset:asset
                                               presetName:AVAssetExportPresetHighestQuality
                                                  success:^(NSString *outputPath) {
        XMLog(@"视频导出到本地完成,沙盒路径为:%@", outputPath);
        [XMUploadManager.sharedInstance uploadWithFilePath:outputPath type:(XMUploadTypeVideo) person_id:self.userModel.person_id complete:^(XMUploadResultModel * _Nonnull result) {
            if (result.success) {
                NSString *videoJson = [[XMUploadResultModel paramDic:result fileType:@"3"] jsonStringEncoded];
                XMWeakSelf(self);
                [self updateUserInfoWithType:(XMEditUserTypeVideo) content:videoJson complete:^(XMResponseTip *tip, id  _Nullable result) {
                    XMStrongSelf(self);
                    if (tip.success) {
                        self.videoView.goLa.text = @"去更换";
                        self.videoView.titleLa.textColor = kHEX(@"1F1F1F");
                        self.videoView.titleLa.text = @"已录制视频封面";
                    }
                }];
            } else {
                [MBProgressHUD hideHUD];
                [MBProgressHUD showHUDMsg:@"视频上传失败请重试!" toView:nil];
            }
        }];
        
    }
                                                  failure:^(NSString *errorMessage, NSError *error) {
        [MBProgressHUD hideHUD];
        XMLog(@"视频导出失败:%@,error:%@", errorMessage, error);
    }];
    
}

// Decide album show or not't
// 决定相册显示与否
- (BOOL)isAlbumCanSelect:(NSString *)albumName result:(PHFetchResult *)result {
    /*
     if ([albumName isEqualToString:@"个人收藏"]) {
     return NO;
     }
     if ([albumName isEqualToString:@"视频"]) {
     return NO;
     }*/
    return YES;
}

// Decide asset show or not't
// 决定asset显示与否
- (BOOL)isAssetCanBeDisplayed:(PHAsset *)asset {
    /*
     switch (asset.mediaType) {
     case PHAssetMediaTypeVideo: {
     // 视频时长
     // NSTimeInterval duration = phAsset.duration;
     return NO;
     } break;
     case PHAssetMediaTypeImage: {
     // 图片尺寸
     if (asset.pixelWidth > 3000 || asset.pixelHeight > 3000) {
     return NO;
     }
     return YES;
     } break;
     case PHAssetMediaTypeAudio:
     return NO;
     break;
     case PHAssetMediaTypeUnknown:
     return NO;
     break;
     default: break;
     }
     */
    return YES;
}

// Decide asset can be selected
// 决定照片能否被选中
- (BOOL)isAssetCanBeSelected:(PHAsset *)asset {
    switch (asset.mediaType) {
        case PHAssetMediaTypeVideo: {
            // 视频时长
            NSTimeInterval duration = asset.duration;
            if (duration > 20) {
                UIAlertController *alertController = [UIAlertController alertControllerWithTitle:@"视频长度不能超过20s" message:nil preferredStyle:UIAlertControllerStyleAlert];
                [alertController addAction:[UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDefault handler:nil]];
                [self.presentedViewController presentViewController:alertController animated:YES completion:nil];
                return NO;
            }
            return YES;
        } break;
        case PHAssetMediaTypeImage: {
            // 图片尺寸
            //            if (asset.pixelWidth > 3000 || asset.pixelHeight > 3000) {
            //                UIAlertController *alertController = [UIAlertController alertControllerWithTitle:@"不支持选择超大图片" message:nil preferredStyle:UIAlertControllerStyleAlert];
            //                [alertController addAction:[UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDefault handler:nil]];
            //                [self.presentedViewController presentViewController:alertController animated:YES completion:nil];
            //                return NO;
            //            }
            return YES;
        } break;
        case PHAssetMediaTypeAudio:
            return NO;
            break;
        case PHAssetMediaTypeUnknown:
            return NO;
            break;
        default: break;
    }
}

#pragma mark - viewBlock
- (void)viewBlock {
    XMWeakSelf(self);
    self.videoView.clickBlock = ^{
        XMStrongSelf(self);
        [self showImagePickerType:2];
    };
    self.headerView.chooseBlock = ^{
        XMStrongSelf(self);
        [GKCover coverFrom:self.view contentView:self.tipView style:(GKCoverStyleTranslucent) showStyle:(GKCoverShowStyleCenter) showAnimStyle:(GKCoverShowAnimStyleNone) hideAnimStyle:(GKCoverHideAnimStyleNone) notClick:YES];
    };
    
    [self.tipView actionTakeBlock:^{
        XMStrongSelf(self);
        [self takePhoto];
    } chooseBlock:^{
        XMStrongSelf(self);
        [self showImagePickerType:1];
    } cancelBlock:^{
        [GKCover hideCover];
    }];
    
    self.nameView.clickBlock = ^{
        XMStrongSelf(self);
        [GKCover coverFrom:self.view contentView:self.editNameView style:(GKCoverStyleTranslucent) showStyle:(GKCoverShowStyleCenter) showAnimStyle:(GKCoverShowAnimStyleNone) hideAnimStyle:(GKCoverHideAnimStyleNone) notClick:YES];
    };
    
    self.signView.clickBlock = ^{
        XMStrongSelf(self);
        [GKCover coverFrom:self.view contentView:self.editSignView style:(GKCoverStyleTranslucent) showStyle:(GKCoverShowStyleCenter) showAnimStyle:(GKCoverShowAnimStyleNone) hideAnimStyle:(GKCoverHideAnimStyleNone) notClick:YES];
    };
    
    self.ageView.clickBlock = ^{
        XMStrongSelf(self);
        BRStringPickerView *stringPickerView = [[BRStringPickerView alloc] init];
        stringPickerView.pickerMode = BRStringPickerComponentSingle;
        stringPickerView.title = @"选择年龄";
        stringPickerView.dataSourceArr = [self ageArray];
        if (self.ageView.contentStr.length > 0) {
            NSString *str = self.ageView.contentStr;
            if ([str containsString:@"岁"]) {
                str = [str stringByReplacingOccurrencesOfString:@"岁" withString:@""];
            }
            stringPickerView.selectIndex = [[self ageArray] indexOfObject:str];
        }
        XMWeakSelf(self);
        stringPickerView.resultModelBlock = ^(BRResultModel *resultModel) {
            XMStrongSelf(self);
            XMWeakSelf(self);
            [self updateUserInfoWithType:XMEditUserTypeAge content:resultModel.value complete:^(XMResponseTip *tip, id  _Nullable result) {
                XMStrongSelf(self);
                if (tip.success) {
                    self.ageView.contentStr = kStringFormat(@"%@岁",resultModel.value);
                    kUserModel.age = resultModel.value;
                }
            }];
        };
        stringPickerView.pickerStyle = [self pickerStyle];
        [stringPickerView show];
    };
    
    self.birView.clickBlock = ^{
        XMStrongSelf(self);
        BRDatePickerView *datePickerView = [[BRDatePickerView alloc]init];
        datePickerView.pickerMode = BRDatePickerModeYMD;
        datePickerView.title = @"选择生日";
        if ([self.birView.contentStr containsString:@"-"]) {
            datePickerView.selectValue = self.birView.contentStr;
        }
        // datePickerView.selectValue = @"2019-10-30";
        //        datePickerView.selectDate = [NSDate br_setYear:2019 month:10 day:30];
        datePickerView.minDate = [NSDate br_setYear:1949 month:3 day:12];
        datePickerView.maxDate = [NSDate date];
        datePickerView.isAutoSelect = NO;
        XMWeakSelf(self);
        datePickerView.resultBlock = ^(NSDate *selectDate, NSString *selectValue) {
            XMStrongSelf(self);
            NSLog(@"选择的值：%@", selectValue);
            XMWeakSelf(self);
            [self updateUserInfoWithType:XMEditUserTypeBirthday content:selectValue complete:^(XMResponseTip *tip, id  _Nullable result) {
                XMStrongSelf(self);
                if (tip.success) {
                    self.birView.contentStr = selectValue;
                    kUserModel.birthday = selectValue;
                }
            }];
        };
        datePickerView.pickerStyle = [self pickerStyle];
        // 3.显示
        [datePickerView show];
    };
    
    self.cityView.clickBlock = ^{
        XMStrongSelf(self);
        BRAddressPickerView *addressPickerView = [[BRAddressPickerView alloc] init];
        addressPickerView.pickerMode = BRAddressPickerModeCity;
        addressPickerView.title = @"请选择城市";
        if (self.cityView.contentStr.length > 0) {
            addressPickerView.selectValues = [self.cityView.contentStr componentsSeparatedByString:@" "];
        }
        XMWeakSelf(self);
        addressPickerView.resultBlock = ^(BRProvinceModel *province, BRCityModel *city, BRAreaModel *area) {
            XMStrongSelf(self);
            NSString *content = [XMUtil isBlankString:city.name] ? province.name : [NSString stringWithFormat:@"%@ %@", province.name, city.name];
            [self updateUserInfoWithType:XMEditUserTypeCity content:content complete:^(XMResponseTip *tip, id  _Nullable result) {
                XMStrongSelf(self);
                if (tip.success) {
                    self.cityView.contentStr = content;
                    kUserModel.birthday = content;
                }
            }];
        };
        addressPickerView.pickerStyle = [self pickerStyle];
        [addressPickerView show];
    };
    
    self.heightView.clickBlock = ^{
        XMStrongSelf(self);
        [self showHeightChooseV];
    };
    
    self.xueliView.clickBlock = ^{
        XMStrongSelf(self);
        BRStringPickerView *stringPickerView = [[BRStringPickerView alloc] init];
        stringPickerView.pickerMode = BRStringPickerComponentSingle;
        stringPickerView.title = @"选择学历";
        stringPickerView.dataSourceArr = [self xueliArray];
        if (self.xueliView.contentStr.length > 0) {
            NSString *str = self.xueliView.contentStr;
            stringPickerView.selectIndex = [[self xueliArray] indexOfObject:str];
        }
        XMWeakSelf(self);
        stringPickerView.resultModelBlock = ^(BRResultModel *resultModel) {
            XMStrongSelf(self);
            XMWeakSelf(self);
            [self updateUserInfoWithType:XMEditUserTypeXueLi content:resultModel.value complete:^(XMResponseTip *tip, id  _Nullable result) {
                XMStrongSelf(self);
                if (tip.success) {
                    self.xueliView.contentStr = resultModel.value;
                    kUserModel.education = resultModel.value;
                }
            }];
        };
        stringPickerView.pickerStyle = [self pickerStyle];
        [stringPickerView show];
    };
    
    self.zhiyeView.clickBlock = ^{
        XMStrongSelf(self);
        BRStringPickerView *stringPickerView = [[BRStringPickerView alloc] init];
        stringPickerView.pickerMode = BRStringPickerComponentSingle;
        stringPickerView.title = @"选择职业";
        stringPickerView.dataSourceArr = [self zhiyeArray];
        if (self.zhiyeView.contentStr.length > 0) {
            NSString *str = self.zhiyeView.contentStr;
            stringPickerView.selectIndex = [[self zhiyeArray] indexOfObject:str];
        }
        XMWeakSelf(self);
        stringPickerView.resultModelBlock = ^(BRResultModel *resultModel) {
            XMStrongSelf(self);
            [self updateUserInfoWithType:XMEditUserTypeZhiYe content:resultModel.value complete:^(XMResponseTip *tip, id  _Nullable result) {
                XMStrongSelf(self);
                if (tip.success) {
                    self.zhiyeView.contentStr = resultModel.value;
                    kUserModel.occupation = resultModel.value;
                }
            }];
        };
        stringPickerView.pickerStyle = [self pickerStyle];
        [stringPickerView show];
    };
    
    //
    self.qingganView.clickBlock = ^{
        XMStrongSelf(self);
        BRStringPickerView *stringPickerView = [[BRStringPickerView alloc] init];
        stringPickerView.pickerMode = BRStringPickerComponentSingle;
        stringPickerView.title = @"情感状态";
        stringPickerView.dataSourceArr = [self qingganArray];
        if (self.qingganView.contentStr.length > 0) {
            NSString *str = self.qingganView.contentStr;
            stringPickerView.selectIndex = [[self qingganArray] indexOfObject:str];
        }
        XMWeakSelf(self);
        stringPickerView.resultModelBlock = ^(BRResultModel *resultModel) {
            XMStrongSelf(self);
            [self updateUserInfoWithType:XMEditUserTypeQingGan content:resultModel.value complete:^(XMResponseTip *tip, id  _Nullable result) {
                XMStrongSelf(self);
                if (tip.success) {
                    self.qingganView.contentStr = resultModel.value;
                    kUserModel.emotion = resultModel.value;
                }
            }];
        };
        stringPickerView.pickerStyle = [self pickerStyle];
        [stringPickerView show];
    };
    
    self.shouruView.clickBlock = ^{
        XMStrongSelf(self);
        BRStringPickerView *stringPickerView = [[BRStringPickerView alloc] init];
        stringPickerView.pickerMode = BRStringPickerComponentSingle;
        stringPickerView.title = @"月收入";
        stringPickerView.dataSourceArr = [self shouruArray];
        if (self.shouruView.contentStr.length > 0) {
            NSString *str = self.shouruView.contentStr;
            stringPickerView.selectIndex = [[self shouruArray] indexOfObject:str];
        }
        XMWeakSelf(self);
        stringPickerView.resultModelBlock = ^(BRResultModel *resultModel) {
            XMStrongSelf(self);
            [self updateUserInfoWithType:XMEditUserTypeShouRu content:resultModel.value complete:^(XMResponseTip *tip, id  _Nullable result) {
                XMStrongSelf(self);
                if (tip.success) {
                    self.shouruView.contentStr = resultModel.value;
                    kUserModel.income = resultModel.value;
                }
            }];
        };
        stringPickerView.pickerStyle = [self pickerStyle];
        [stringPickerView show];
    };
    
    self.fangView.clickBlock = ^{
        XMStrongSelf(self);
        BRStringPickerView *stringPickerView = [[BRStringPickerView alloc] init];
        stringPickerView.pickerMode = BRStringPickerComponentSingle;
        stringPickerView.title = @"有无房产";
        stringPickerView.dataSourceArr = [self fangArray];
        if (self.fangView.contentStr.length > 0) {
            NSString *str = self.fangView.contentStr;
            stringPickerView.selectIndex = [[self fangArray] indexOfObject:str];
        }
        XMWeakSelf(self);
        stringPickerView.resultModelBlock = ^(BRResultModel *resultModel) {
            XMStrongSelf(self);
            [self updateUserInfoWithType:XMEditUserTypeFang content:resultModel.value complete:^(XMResponseTip *tip, id  _Nullable result) {
                XMStrongSelf(self);
                if (tip.success) {
                    self.fangView.contentStr = resultModel.value;
                    kUserModel.purchase_house = resultModel.value;
                }
            }];
        };
        stringPickerView.pickerStyle = [self pickerStyle];
        [stringPickerView show];
    };
    
    self.cheView.clickBlock = ^{
        XMStrongSelf(self);
        BRStringPickerView *stringPickerView = [[BRStringPickerView alloc] init];
        stringPickerView.pickerMode = BRStringPickerComponentSingle;
        stringPickerView.title = @"是否购车";
        stringPickerView.dataSourceArr = [self cheArray];
        if (self.cheView.contentStr.length > 0) {
            NSString *str = self.cheView.contentStr;
            stringPickerView.selectIndex = [[self cheArray] indexOfObject:str];
        }
        XMWeakSelf(self);
        stringPickerView.resultModelBlock = ^(BRResultModel *resultModel) {
            XMStrongSelf(self);
            [self updateUserInfoWithType:XMEditUserTypeChe content:resultModel.value complete:^(XMResponseTip *tip, id  _Nullable result) {
                XMStrongSelf(self);
                if (tip.success) {
                    self.cheView.contentStr = resultModel.value;
                    kUserModel.buying_car = resultModel.value;
                }
            }];
        };
        stringPickerView.pickerStyle = [self pickerStyle];
        [stringPickerView show];
    };
    
    self.techangView.clickBlock = ^{
        XMStrongSelf(self);
        BRStringPickerView *stringPickerView = [[BRStringPickerView alloc] init];
        stringPickerView.pickerMode = BRStringPickerComponentSingle;
        stringPickerView.title = @"特长";
        stringPickerView.dataSourceArr = [self aihaoArray];
        if (self.techangView.contentStr.length > 0) {
            NSString *str = self.techangView.contentStr;
            stringPickerView.selectIndex = [[self aihaoArray] indexOfObject:str];
        }
        XMWeakSelf(self);
        stringPickerView.resultModelBlock = ^(BRResultModel *resultModel) {
            XMStrongSelf(self);
            [self updateUserInfoWithType:XMEditUserTypeTeChang content:resultModel.value complete:^(XMResponseTip *tip, id  _Nullable result) {
                XMStrongSelf(self);
                if (tip.success) {
                    self.techangView.contentStr = resultModel.value;
                    kUserModel.hobby = resultModel.value;
                }
            }];
        };
        stringPickerView.pickerStyle = [self pickerStyle];
        [stringPickerView show];
    };
    
    
    self.heightChooseV.cancelBlock = ^{
        [GKCover hideCover];
    };
    self.heightChooseV.sureBlock = ^(NSString * _Nonnull hStr, NSString * _Nonnull wStr) {
        XMStrongSelf(self);
        XMWeakSelf(self);
        [GKCover hideCoverWithHideBlock:^{
            XMStrongSelf(self);
            [self updateUserInfoWithType:XMEditUserTypeHWeight content:kStringFormat(@"%@-%@", hStr, wStr) complete:^(XMResponseTip *tip, id  _Nullable result) {
                XMStrongSelf(self);
                if (tip.success) {
                    self.heightView.contentStr = kStringFormat(@"%@-%@", hStr, wStr);
                    kUserModel.weight = wStr;
                    kUserModel.height = hStr;
                }
            }];
        }];
    };
    
    self.editNameView.sureBlock = ^(NSString * _Nonnull str) {
        XMStrongSelf(self);
        if ([XMUtil isBlankString:str]) {
            [MBProgressHUD showHUDMsg:@"请输入昵称" toView:nil];
            return;
        }
        [self updateUserInfoWithType:XMEditUserTypeName content:str complete:^(XMResponseTip *tip, id  _Nullable result) {
            XMStrongSelf(self);
            if (tip.success) {
                self.nameView.contentStr = str;
                self.nameView.stateBtn.hidden = NO;
                kUserModel.nickname = str;
                [GKCover hideCover];
            }
        }];
    };
    
    self.editNameView.closeBlock = ^{
        [GKCover hideCover];
    };
    
    self.editSignView.sureBlock = ^(NSString * _Nonnull str) {
        XMStrongSelf(self);
        if ([XMUtil isBlankString:str]) {
            [MBProgressHUD showHUDMsg:@"请输入个性签名!" toView:nil];
            return;
        }
        [self updateUserInfoWithType:XMEditUserTypeSign content:str complete:^(XMResponseTip *tip, id  _Nullable result) {
            XMStrongSelf(self);
            if (tip.success) {
                self.signView.contentStr = str;
                kUserModel.text_intro = str;
                [GKCover hideCover];
            }
        }];
    };
    
    self.editSignView.closeBlock = ^{
        [GKCover hideCover];
    };
    
    self.voiceView.clickBlock = ^{
        XMStrongSelf(self);
        if ([XMUtil isBlankString:self.userModel.voice_intro.file_url]) {
            [self showRecordView];
        } else {
            [GKCover coverFrom:self.view contentView:self.voiceTipView style:(GKCoverStyleTranslucent) showStyle:(GKCoverShowStyleCenter) showAnimStyle:(GKCoverShowAnimStyleNone) hideAnimStyle:(GKCoverHideAnimStyleNone) notClick:YES];
        }
        
    };
    
    self.voiceView.iconBlock = ^{
        XMStrongSelf(self);
        if (![XMUtil isBlankString:self.filePath]) {
            dispatch_async(dispatch_get_global_queue(0, 0), ^{
                NSData *data =
                [[NSData alloc] initWithContentsOfURL:[NSURL fileURLWithPath:self.filePath]];
                [[XMAudioPlayer sharedInstance] startPlayVoiceData:data time:0];
            });
        } else {
            if (![XMUtil isBlankString:self.userModel.voice_intro.file_url]) {
                XMLog(@"%@",self.userModel.voice_intro.file_url);
                if (![XMAudioPlayer.sharedInstance isPlaying]) {
                    dispatch_async(dispatch_get_global_queue(0, 0), ^{
                        NSData *data =
                        [[NSData alloc] initWithContentsOfURL:kStringToUrl(self.userModel.voice_intro.file_url)];
                        [[XMAudioPlayer sharedInstance] startPlayVoiceData:data time:0];
                    });
                    
                }
            }
            
        }
    };
    
    [self.voiceTipView tipViewLeftBlock:^{
        [GKCover hideCover];
    } rightBlock:^{
        XMStrongSelf(self);
        XMWeakSelf(self);
        [GKCover hideCoverWithHideBlock:^{
            XMStrongSelf(self);
            [self showRecordView];
        }];
    }];
    
    self.jieshaoView.clickBlock = ^{
        XMStrongSelf(self);
        XMIntroduceViewController *vc = [[XMIntroduceViewController alloc] initWithNibName:kStringFromClass(XMIntroduceViewController) bundle:nil];
        if (![XMUtil isBlankString:self.userModel.introduce]) {
            vc.introduce = self.userModel.introduce;
        }
        [self.navigationController pushViewController:vc animated:YES];
        
        vc.saveBlock = ^(NSString * _Nonnull introduce) {
            
        };
    };
    
    self.photoView.clickBlock = ^{
        XMStrongSelf(self);
        XMRecentPhotosListViewController *vc = [[XMRecentPhotosListViewController alloc] initWithNibName:kStringFromClass(XMRecentPhotosListViewController) bundle:nil];
        [self.navigationController pushViewController:vc animated:YES];
    };
}

- (void)showRecordView {
    XMLoginRecordView *recordView = [XMLoginRecordView viewFromXib];
    recordView.size = CGSizeMake(kScreenWidth, kScreenHeight);
    [GKCover coverFrom:self.view
           contentView:recordView
                 style:GKCoverStyleTranslucent
             showStyle:GKCoverShowStyleCenter
         showAnimStyle:GKCoverShowAnimStyleNone
         hideAnimStyle:GKCoverHideAnimStyleNone
              notClick:NO];
    
    recordView.completeBlock = ^(NSString *_Nonnull filePath, NSInteger voiceLength) {
        [MBProgressHUD showHUDActivityMsg:nil toView:kWindow];
        [XMUploadManager.sharedInstance uploadWithFilePath:filePath type:(XMUploadTypeAudio) person_id:self.userModel.person_id complete:^(XMUploadResultModel * _Nonnull result) {
            if (result.success) {
                NSMutableDictionary *dic = [XMUploadResultModel paramDic:result fileType:@"2"];
                [dic setObject:@(voiceLength) forKey:@"voice_length"];
                NSString *voiceJson = [dic jsonStringEncoded];
                XMWeakSelf(self);
                [self updateUserInfoWithType:(XMEditUserTypeVoice) content:voiceJson complete:^(XMResponseTip *tip, id  _Nullable result1) {
                    XMStrongSelf(self);
                    if (tip.success) {
                        [GKCover hideCover];
                        self.filePath = filePath;
                        self.voiceView.goLa.text = @"去更换";
                        self.voiceView.icon.image = kGetImage(@"edit_voice1");
                        self.voiceView.titleLa.textColor = kHEX(@"1F1F1F");
                        self.voiceView.titleLa.text = @"播放已录的语音";
                        self.userModel.voice_intro.file_url = result.url;
                    }
                }];
            } else {
                [MBProgressHUD hideHUD];
                [MBProgressHUD showHUDMsg:@"录音上传失败!" toView:nil];
            }
        }];
    };
    
    recordView.closeBlock = ^{
        [GKCover hideCover];
        
    };
}

- (void)updateUserInfoWithType:(XMEditUserType)type
                       content:(NSString *)content
                      complete:(void(^)(XMResponseTip *tip, id _Nullable result))complete {
    
    [MBProgressHUD showHUDActivityMsg:nil toView:kWindow];
    NSMutableDictionary *dic = @{}.mutableCopy;
    
    if (type == XMEditUserTypeHeader) {
        [dic setObject:[NSString xm_stringNoNullWith:content] forKey:@"avatar"];
    }
    
    if (type == XMEditUserTypeName) {
        [dic setObject:[NSString xm_stringNoNullWith:content] forKey:@"nickname"];
    }
    
    if (type == XMEditUserTypeSign) {
        [dic setObject:[NSString xm_stringNoNullWith:content] forKey:@"text_intro"];
    }
    
    if (type == XMEditUserTypeVoice) {
        [dic setObject:[NSString xm_stringNoNullWith:content] forKey:@"voice_intro"];
    }
    if (type == XMEditUserTypeVideo) {
        [dic setObject:[NSString xm_stringNoNullWith:content] forKey:@"video_cover"];
    }
    if (type == XMEditUserTypeDesc) {
        [dic setObject:[NSString xm_stringNoNullWith:content] forKey:@"introduce"];
    }
    if (type == XMEditUserTypeAge) {
        [dic setObject:[NSString xm_stringNoNullWith:content] forKey:@"age"];
    }
    if (type == XMEditUserTypeBirthday) {
        [dic setObject:[NSString xm_stringNoNullWith:content] forKey:@"birthday"];
    }
    if (type == XMEditUserTypeCity) {
        if (![content containsString:@" "]) {
            [dic setObject:[NSString xm_stringNoNullWith:content] forKey:@"province"];
            [dic setObject:[NSString xm_stringNoNullWith:@""] forKey:@"city"];
        } else {
            NSArray *arr = [content componentsSeparatedByString:@" "];
            [dic setObject:[NSString xm_stringNoNullWith:arr.firstObject] forKey:@"province"];
            [dic setObject:[NSString xm_stringNoNullWith:arr.lastObject] forKey:@"city"];
        }
    }
    if (type == XMEditUserTypeHWeight) {
        NSString *wStr = @"";
        NSString *hStr = @"";
        if ([content containsString:@"cm"] &&
            [content containsString:@"-"] &&
            [content containsString:@"kg"]) {
            content = [content stringByReplacingOccurrencesOfString:@"cm" withString:@""];
            content = [content stringByReplacingOccurrencesOfString:@"kg" withString:@""];
            NSArray *arr = [content componentsSeparatedByString:@"-"];
            hStr = arr.firstObject;
            wStr = arr.lastObject;
        }
        [dic setObject:[NSString xm_stringNoNullWith:hStr] forKey:@"height"];
        [dic setObject:[NSString xm_stringNoNullWith:wStr] forKey:@"weight"];
    }
    if (type == XMEditUserTypeXueLi) {
        [dic setObject:[NSString xm_stringNoNullWith:content] forKey:@"education"];
    }
    if (type == XMEditUserTypeZhiYe) {
        [dic setObject:[NSString xm_stringNoNullWith:content] forKey:@"occupation"];
    }
    if (type == XMEditUserTypeQingGan) {
        [dic setObject:[NSString xm_stringNoNullWith:content] forKey:@"emotion"];
    }
    if (type == XMEditUserTypeTeChang) {
        [dic setObject:[NSString xm_stringNoNullWith:content] forKey:@"hobby"];
    }
    if (type == XMEditUserTypeShouRu) {
        [dic setObject:[NSString xm_stringNoNullWith:content] forKey:@"income"];
    }
    if (type == XMEditUserTypeChe) {
        [dic setObject:[NSString xm_stringNoNullWith:content] forKey:@"buying_car"];
    }
    if (type == XMEditUserTypeFang) {
        [dic setObject:[NSString xm_stringNoNullWith:content] forKey:@"purchase_house"];
    }
    [YHNetworkManager.sharedInstance postWithUrl:@"api/user/update" parameters:dic completeBlock:^(XMResponseTip * _Nonnull tip, id  _Nullable result) {
        if (tip.success) {
            [MBProgressHUD hideHUD];
        }
        complete(tip, result);
    }];
    
}

- (void)stopPlay {
    if ([XMAudioPlayer sharedInstance].isPlaying) {
        [[XMAudioPlayer sharedInstance] stopPlay];
    }
}

#pragma mark - lazy
- (BRPickerStyle *)pickerStyle {
    BRPickerStyle *customStyle = [[BRPickerStyle alloc] init];
    customStyle.pickerTextColor = k1F1F1F;
    customStyle.selectRowTextColor = kAppMainColor;
    customStyle.separatorColor = kAppMainColor;
    customStyle.topCornerRadius = 20;
    customStyle.titleTextFont = kUIFont(16);
    customStyle.titleTextColor = UIColor.blackColor;
    return customStyle;
}

- (NSMutableArray *)ageArray {
    NSMutableArray *ageArray = [NSMutableArray array];
    for (NSInteger age = 18; age <= 70; age++) {
        [ageArray addObject:kStringFormat(@"%ld", age)];
    }
    return ageArray;
}

- (NSMutableArray *)shouruArray {
    NSMutableArray *shouruArray = @[
        @"请选择",
        @"3K以下",
        @"3–5K",
        @"5–10K",
        @"10–20K",
        @"20–50K",
        @"50K以上",
    ].mutableCopy;
    return shouruArray;
}

- (NSMutableArray *)qingganArray {
    NSMutableArray *emotionArray = @[@"请选择", @"单身", @"恋爱中"].mutableCopy;
    return emotionArray;
}

- (NSMutableArray *)zhiyeArray {
    NSMutableArray *occupationArray = @[@"白领",
                                        @"飞行员",
                                        @"工程师",
                                        @"公务员",
                                        @"护士",
                                        @"教师",
                                        @"警察",
                                        @"会计",
                                        @"律师",
                                        @"模特",
                                        @"企业高管",
                                        @"私企老板",
                                        @"设计师",
                                        @"行政",
                                        @"医生",
                                        @"自由职业"]
        .mutableCopy;
    return occupationArray;
}

- (NSMutableArray *)fangArray {
    NSMutableArray *houseArray = @[@"请选择", @"有房产", @"无房产"].mutableCopy;
    return houseArray;
}

- (NSMutableArray *)cheArray {
    NSMutableArray *houseArray = @[@"请选择", @"有车", @"无车"].mutableCopy;
    return houseArray;
}

- (NSMutableArray *)sexArray {
    NSMutableArray *acceptArray = @[@"男", @"女"].mutableCopy;
    return acceptArray;
}

- (NSMutableArray *)xueliArray {
    NSMutableArray *xueliArray = @[
        @"博士",
        @"硕士",
        @"本科",
        @"大专",
        @"高中",
        @"小学"
    ].mutableCopy;
    return xueliArray;
}

- (NSMutableArray *)aihaoArray {
    NSMutableArray *aihaoArray = @[
        @"请选择",
        @"跳舞",
        @"画画",
        @"读书",
        @"收藏",
        @"跑步",
        @"骑马",
        @"赛车",
        @"攀岩",
        @"篮球",
        @"露营",
        @"足球",
        @"台球",
        @"高尔夫",
        @"潜水",
        @"游泳",
        @"钓鱼",
        @"瑜伽",
        @"陶艺",
        @"茶艺",
        @"吉他",
        @"古筝",
        @"游戏",
    ].mutableCopy;
    return aihaoArray;
}

- (XMHeightChooseView *)heightChooseV {
    if (_heightChooseV == nil) {
        _heightChooseV = [XMHeightChooseView viewFromXib];
        _heightChooseV.size = CGSizeMake(kScreenWidth, 288);
    }
    return _heightChooseV;
}

- (void)showHeightChooseV {
    [GKCover coverFrom:self.view contentView:self.heightChooseV style:(GKCoverStyleTranslucent) showStyle:(GKCoverShowStyleBottom) showAnimStyle:(GKCoverShowAnimStyleNone) hideAnimStyle:(GKCoverHideAnimStyleNone) notClick:YES];
    
}

- (XMUserDetailRemarkView *)editNameView {
    if (_editNameView == nil) {
        _editNameView = [XMUserDetailRemarkView viewFromXib];
        _editNameView.type = XMEditUserInputTypeNickname;
        _editNameView.size = CGSizeMake(kScreenWidth, kScreenHeight);
    }
    return _editNameView;
}

- (XMUserDetailRemarkView *)editSignView {
    if (_editSignView == nil) {
        _editSignView = [XMUserDetailRemarkView viewFromXib];
        _editSignView.type = XMEditUserInputTypeSign;
        _editSignView.size = CGSizeMake(kScreenWidth, kScreenHeight);
    }
    return _editSignView;
}

- (XMLoginPrivacyTipView *)voiceTipView {
    if (_voiceTipView == nil) {
        _voiceTipView = [XMLoginPrivacyTipView viewFromXib];
        _voiceTipView.size = CGSizeMake(295, 177);
        [_voiceTipView setupEditVoice];
    }
    return _voiceTipView;
}

- (XMChooseHeadTipView *)tipView {
    if (!_tipView) {
        _tipView = [XMChooseHeadTipView viewFromXib];
        _tipView.size = CGSizeMake(kScreenWidth, kScreenHeight);
    }
    return _tipView;
}
@end
